home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH5 / EMAGA5 / common / server / missionInfo.cs < prev    next >
Text File  |  2005-11-23  |  3KB  |  89 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //------------------------------------------------------------------------------
  7. // Loading info is text displayed on the client side while the mission
  8. // is being loaded.  This information is extracted from the mission file
  9. // and sent to each the client as it joins.
  10. //------------------------------------------------------------------------------
  11.  
  12. //------------------------------------------------------------------------------
  13. // clearLoadInfo
  14. //
  15. // Clears the mission info stored
  16. //------------------------------------------------------------------------------
  17. function clearLoadInfo() {
  18.    if (isObject(MissionInfo))
  19.       MissionInfo.delete();
  20. }
  21.  
  22. //------------------------------------------------------------------------------
  23. // buildLoadInfo
  24. //
  25. // Extract the map description from the .mis file
  26. //------------------------------------------------------------------------------
  27. function buildLoadInfo( %mission ) {
  28.     clearLoadInfo();
  29.  
  30.     %infoObject = "";
  31.     %file = new FileObject();
  32.  
  33.     if ( %file.openForRead( %mission ) ) {
  34.         %inInfoBlock = false;
  35.         
  36.         while ( !%file.isEOF() ) {
  37.             %line = %file.readLine();
  38.             %line = trim( %line );
  39.             
  40.             if( %line $= "new ScriptObject(MissionInfo) {" )
  41.                 %inInfoBlock = true;
  42.             else if( %inInfoBlock && %line $= "};" ) {
  43.                 %inInfoBlock = false;
  44.                 %infoObject = %infoObject @ %line; 
  45.                 break;
  46.             }
  47.             
  48.             if( %inInfoBlock )
  49.                %infoObject = %infoObject @ %line @ " ";
  50.         }
  51.         
  52.         %file.close();
  53.     }
  54.  
  55.    // Will create the object "MissionInfo"
  56.     eval( %infoObject );
  57.     %file.delete();
  58. }
  59.  
  60. //------------------------------------------------------------------------------
  61. // dumpLoadInfo
  62. //
  63. // Echo the mission information to the console
  64. //------------------------------------------------------------------------------
  65. function dumpLoadInfo()
  66. {
  67.     echo( "Mission Name: " @ MissionInfo.name );
  68.    echo( "Mission Description:" );
  69.    
  70.    for( %i = 0; MissionInfo.desc[%i] !$= ""; %i++ )
  71.       echo ("   " @ MissionInfo.desc[%i]);
  72. }
  73.  
  74. //------------------------------------------------------------------------------
  75. // sendLoadInfoToClient
  76. //
  77. // Sends mission description to the client
  78. //------------------------------------------------------------------------------
  79. function sendLoadInfoToClient( %client )
  80. {
  81.    messageClient( %client, 'MsgLoadInfo', "", MissionInfo.name );
  82.  
  83.    // Send Mission Description a line at a time
  84.    for( %i = 0; MissionInfo.desc[%i] !$= ""; %i++ )
  85.      messageClient( %client, 'MsgLoadDescripition', "", MissionInfo.desc[%i] );
  86.  
  87.    messageClient( %client, 'MsgLoadInfoDone' );
  88. }
  89.